package com.zxb.base.auth;

import cn.hutool.core.util.StrUtil;
import com.zxb.core.common.R;
import com.zxb.core.common.Req;
import com.zxb.core.common.User;
import com.zxb.core.dao.auth.AuthUser;
import com.zxb.core.dao.auth.AuthUserDao;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zxb
 */
@RestController
@RequiredArgsConstructor
public class GestureController {

    private final AuthUserDao userDao;

    @PostMapping("/user/gesture/change")
    public R changeGesture(@RequestBody String gesture) {
        if (StrUtil.isBlank(gesture)) {
            return R.error("请输入手势密码");
        }
        User u = Req.getCurrUser();
        AuthUser user = userDao.getById(u.getId());
        user.setGesture(gesture);
        userDao.updateById(user);
        return R.success();
    }

}
